<template>
	<div class="add-order">
		<div>
			<label>{{ $t('route.base') }}</label>
			<div></div>
			<button><img /><label>添加程序</label></button>
		</div>
		<div>
			<el-form ref="form" label-width="100px">
				<el-form label-width="100px">
					<el-form-item label="上传程序包">
						<!-- <el-upload style="margin-left: 20px;" accept="image/*" :action="uploadUrl" :show-file-list="false"
							:on-success="uploadSuccess">
						</el-upload> -->
						<el-upload class="upload-demo" drag data="file" :on-success="uploadSuccess"
							action="http://file.chinahikari.com:8686/hikari-cloud/file-mgr/base/uploadFile?type=2"
							:multiple="false">
							<div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
						</el-upload>
					</el-form-item>
					<el-form-item label="程序名称">
						<el-input v-model="form.name" />
					</el-form-item>
					<el-form-item label="版本名字">
						<el-input v-model="form.versionName" />
					</el-form-item>
					<el-form-item label="版本号">
						<el-input onkeyup="value=value.replace(/[^\d]/g,0)" v-model="form.versionCode" />
					</el-form-item>
					<el-form-item label="类型">
						<el-select v-model="form.type" filterable placeholder="请选择">
							<el-option v-for="item in PORARM_TYPE" :key="item.value" :label="item.name"
								:value="item.value" />
						</el-select>
					</el-form-item>
					<el-form-item label="备注">
						<el-input v-model="form.message" />
					</el-form-item>
					<el-form-item>
						<el-button style="width: 100%;" type="primary" @click="addClick">{{ $t('route.Add') }}</el-button>
					</el-form-item>
				</el-form>
			</el-form>
		</div>

	</div>
</template>

<script>
import http from "../../js/http/http.js";
import api from "../../js/http/api.js";
import CommonUtils from "../../js/common/common-utils";
import Constant from '../../js/common/constant.js'

export default {
	data() {
		return {
			form: {
				name: null,
				versionName: null,
				versionCode: null,
				url: null,
				type: null,
				message: null,
			},
			PORARM_TYPE: Constant.PORARM_TYPE
		}
	},

	methods: {
		uploadSuccess(response, file, fileList) {
			this.form.url = response.data;
		},
		addClick() {
			if (CommonUtils.isEmpty(this.form.url)) {
				this.$message.error("请上传程序包");
				return;
			}
			if (CommonUtils.isEmpty(this.form.name)) {
				this.$message.error("程序名称不能为空");
				return;
			}
			if (CommonUtils.isEmpty(this.form.versionName)) {
				this.$message.error("版本名字不能为空");
				return;
			}
			if (CommonUtils.isEmpty(this.form.versionCode)) {
				this.$message.error("版本序号不能为空");
				return;
			}
			http.post(api.ADD_GROGRAM_DATA, {
				name: this.form.name,
				type: this.form.type,
				versionName: this.form.versionName,
				versionCode: this.form.versionCode,
				url: this.form.url,
				message: this.form.message,

			}, data => {
				this.$message.success("成功添加");
				this.$router.go(-1);
			});
		}
	}
};
</script>
<style lang="scss" scoped>
.add-order {
	color: #444444;
	font-size: 18px;
	padding-right: 20px;
	height: calc(100vh - 100px);
	// overflow: scroll;
	scrollbar-width: none;
	/* firefox */
	-ms-overflow-style: none;
	/* IE 10+ */
	overflow-x: hidden;
	overflow-y: auto;


	>div:nth-of-type(1) {
		display: flex;
		flex-direction: row;
		align-items: center;
		margin-top: 20px;
		background-color: #ffffff;
		padding: 20px;
		border-radius: 5px;

		>label:nth-of-type(1) {
			font-weight: 600;
		}

		>div:nth-of-type(1) {
			width: 1px;
			background-color: #cccccc;
			height: 15px;
			margin: 0px 20px;
		}

		>button:nth-of-type(1) {
			background-image: url(../../assets/img/customer-1.png);
			background-repeat: no-repeat;
			background-size: 100% 100%;
			padding: 5px 10px;
			border: 0px;
			display: flex;
			color: #ffffff;
			flex-direction: row;
			align-items: center;
			font-weight: 800;

			>img {
				margin-right: 7px;
				width: 15px;
				height: 15px;
				content: url(../../assets/img/customer-2.png);
			}

		}
	}

	>div:nth-of-type(2) {
		display: flex;
		flex-direction: row;
		align-items: center;
		margin-top: 20px;
		background-color: #ffffff;
		padding: 20px;
		border-radius: 5px;



		.div-1 {
			display: flex;
			flex-direction: row;

			>label {
				margin-left: 10px;
				width: 200px;
			}
		}


	}





}
</style>
